Skip to content

fix(studio): keep a sealed drag's waiting outline until the frame draws its replay - #8588

Merged
miguel-heygen merged 5 commits into
mainfrom
fix/sealed-press-replay-shows-at-once
Nov 23, 2026
Merged

miguel-heygen merged 5 commits into
mainfrom
fix/sealed-press-replay-shows-at-once

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What

On a sealed preview, a drag pressed while the previous edit was still saving no longer shows the layer back at the drag's start for one frame when the save lands. In the edit bench's back-to-back drag case (resize, move, resize, move on one layer), the layer jumped 312 px on the second and fourth drags; now it follows the pointer the same as unsealed.

Why

A canvas press waits while an edit is saving, in both modes, and replays its moves once the save has landed. Unsealed, the replay redraws the layer in the same task that ends the wait, so no frame paints between them. Sealed, the replay's draw reaches the frame one round trip later. Meanwhile the waiting outline was already gone and the save's own patch had put the layer at the drag's start. That frame, between the outline going and the replay arriving, was the jump.

Related work

Follows #8563, which made the sealed save's patch draw in its own task; that left this frame.

How

The waiting outline on a sealed preview is one small state machine with one owner, pressOutline.ts. There is one outline per overlay mount, keyed by the mount's waitingPressRef and created on first use, so it outlives the handlers the overlay recreates on every render. The handlers in previewGestureStarts.ts hold no outline state; they only send it events (waitOnSave, replayEnded, idle). Each replay's wait is its id, and only the current one may clear the outline.

State Event Next state
idle press while the preview changes waiting on the save (outline on, overlay loop paused)
waiting on the save save ends: the press replays its drag waiting on draw (replay id, frame shown now)
waiting on the save the replayed press doesn't start idle
waiting on the save a second press waiting on the save (queued behind the first, as today)
waiting on draw (id, frame) that frame confirms the draws, id current, still shown idle
waiting on draw (id, frame) that frame confirms, but a reload swapped in another frame waiting on draw (id, the new frame)
waiting on draw (id, frame) a second press waiting on the save; the old id is stale
waiting on draw (id, frame) the overlay leaves or turns read-only (endWaitingPress) idle; the old id is stale
waiting on draw (id, frame) the overlay re-renders, then a press through the new handlers waiting on the save; the old id is stale, since both handler sets share the mount's outline
any a confirmation whose id is stale unchanged

Unsealed presses never enter the draw wait: their replay draws in the same task, so the outline goes when the wait ends, as before. No message to the runtime changes, so an older runtime behaves the same.

No visible change

The interface doesn't change: the layer just no longer jumps when a sealed drag starts during a save.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix:

  • packages/studio/src/components/editor/previewOverlayRects.test.ts: "keeps the waiting outline until the frame has drawn the replayed drag", "keeps the waiting outline until the frame the change swapped in has drawn the replay", "keeps a newer replay's outline when an older replay's frame answers first", "waits on the frame swapped in after the replay, not the one it drew in", "keeps a press's outline made after a re-render when the replay before it answers".

"keeps a press's outline that comes while the replay before it waits on its frame" and "drops the outline at once when the overlay leaves, and a late answer changes nothing" pin the other two stale-confirmation cases in the table.

  • With the fix, that file and gestureHoldsPreviewReload.test.tsx pass three runs in a row on Linux (60 tests). Studio's src/components/editor (182 files, 2,197 tests) passes, and Studio typechecks clean.
  • Edit bench, seqheldtwice root and nested, two runs each, sealed and unsealed, on main and with the fix. The worst box jump per drag on main sealed was up to 312.4 px on drags 2 and 4, and the teleport check failed 4 of 4. With the fix: at most 0.1 px on every drag in both modes, and the teleport check passes 4 of 4, the same as unsealed. The smooth check fails in every run, main unsealed included, so it isn't this change. Rerun with the state machine (aacb2e4), sealed and unsealed: element jumps 0 on every drag and teleport passes in every run.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Wait for the frame that receives the replay. packages/studio/src/components/editor/previewGestureStarts.ts:253 passes the iframe captured at pointer-down to previewDraftsSent. If the save replaces that iframe, askShownFrame reads the replacement and the replay draws into its queue. The old queue can already be empty, so the outline clears before the shown frame draws. I reproduced this by swapping the opaque iframe while the press waited and holding the replacement’s draw. The waiting attribute was already gone. Wait on the frame used by the replay and cover the replacement in the regression test.

Both existing focused suites passed, 54 tests. The replacement-frame probe failed at this head.

— tai (automated review)

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 62 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in 9f82018: the outline now waits on the frame shown when the replay runs, so a frame swapped in during the wait holds it until that frame has drawn. Red row: "keeps the waiting outline until the frame the change swapped in has drawn the replay" (previewOverlayRects.test.ts), failing at 961a15a.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Give each replay ownership of its outline. The single frame-swap case is fixed. At packages/studio/src/components/editor/previewGestureStarts.ts:243–256, an older replay’s completion still clears the shared outline whenever waitingPressRef.current is null. It is also null once a newer replay starts waiting for its own frame to draw. I reproduced this with two replays on different iframe instances. Resolving the older frame’s wait first removed the newer outline while its draw was still pending. Guard cleanup with the press or replay identity that owns the outline, and cover the out-of-order completions.

All 55 existing focused tests passed. The two-replay probe failed at this head.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in aacb2e4, by shape rather than by case: the outline is now one state (idle, waiting on the save, waiting on a replay's draw in a frame). Only the current replay's confirmation can clear it, and a frame swapped in moves the wait to that frame. The table is in the description. Rows: "keeps a newer replay's outline when an older replay's frame answers first" and "waits on the frame swapped in after the replay, not the one it drew in" fail at 9f82018; two more pin a press arriving during the draw wait and the overlay leaving.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Keep replay ownership across overlay renders. packages/studio/src/components/editor/previewGestureStarts.ts:59 stores drawWait in one handler instance. DomEditOverlay.tsx:280 recreates the handlers on render. A newer press can invalidate the wait in its new instance while the old callback still owns the wait in its old instance. I updated the existing second-press test to recreate the handlers with the same refs, as the overlay does. The old frame’s reply removed the outline while the newer press was still waiting. Store the replay identity in overlay-lifetime state shared by the handlers and cleanup, and test a re-render between presses.

All 59 existing focused tests passed. The re-render variant failed at this head.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in af800ee: the outline's state moved out of the handlers into one owner per overlay mount (pressOutline.ts, keyed by the mount's waitingPressRef). Handlers recreated on render share it and only send it events. Your re-render case is in the table and is the row "keeps a press's outline made after a re-render when the replay before it answers", which fails at aacb2e4.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outline owner now survives handler recreation because both handler sets share the mount’s ref. I verified that the re-render regression fails with the previous implementation and passes at this head. All 60 focused tests passed. I did not rerun the browser bench.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactor preserves the outline transitions. A queued press keeps its outline, a sealed replay waits for its frame, and a replay without a frame clears the outline. The mount still owns the state across handler recreation. All 60 focused tests passed. I did not rerun the browser bench.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 2cc423b Nov 23, 2026
86 of 87 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-press-replay-shows-at-once branch November 23, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants